package org.entities;

import org.BlockMap;
import org.StatusState;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;

public class Item extends LevelObject {

    public static Image img,img1,img2,img3;
    public static String info;
    //public static String type;
    private static SpriteSheet sheet1;
    public Item(int x, int y, int test[], String type) throws SlickException {

        super(x,y,				
                x+test[0], y+test[1], 
                x+test[2], y+test[3],
                x+test[4], y+test[5],
                x+test[6], y+test[7],
                type);
        //this.type=type;
        sheet1=new SpriteSheet("data/tileset/items.png",16,16);
        if (type.equals("powerup"))
            img1 = sheet1.getSprite(0,0);
        if (type.equals("quest"))
            img2 = sheet1.getSprite(1,0);
        if (type.equals("manual"))
            img3 = sheet1.getSprite(2,0); 

    }

    public static Image imgSelect(String xyz) throws SlickException{
        if (xyz.equals("powerup")){
            img = sheet1.getSprite(0,0);
        }
        else if (xyz.equals("quest")){
            img = sheet1.getSprite(1,0);
        }       
        else if (xyz.equals("manual")){
            img = sheet1.getSprite(2,0);
        }
        else img=sheet1.getSprite(0,0);
         
        return img;
    }

    public static String infoSelect(String xyz){
        if (xyz.equals("manual"))
            info = "manual:\n" +
            "\n"+
            "Using the Armor consume its\n" +
            "resources. Just by moving around\n" +
            "for a while you will have depleted\n" +
            "all the armor resources\n" +
            "When armor's Energy reaches zero\n" +
            "moving a powerless suit will be\n" +
            "painfull you will progressively\n" +
            "loose health.\n";

        else if (xyz.equals("powerup"))
            info = "cobalt crystal:\n" +
            "Raw material which can restore\n" +
            "Energy when combined with some\n" +
            "other mineral such as iridium";

        else if (xyz.equals("quest"))
            info = "quest item (1)\n" +
            "I've just arrived on Planet Zebes.\n" +
            "I need to find theses parts to\n" +
            "repair my ship:\n" +
            "- Ship energy source\n" +
            "- Some polymere alloy\n" +
            "- And a space com. device\n";
        else
            info = "no info";

        return info;
    }

    public void update(int delta) throws SlickException {

        if (gotHurt){
            System.out.println("item collected");
            StatusState.ctrlLoop=false;
            die();
        }
    }

    public void die() {
        System.out.printf("item must die\n");
        //dieSound.play(1, Progress.sfxVol/20);
        BlockMap.entities.remove(this);
    }


    public boolean isCollisionWith(LevelObject other) { 
        return poly.intersects(other.poly);
    }

    public boolean collidedWith(LevelObject entity) {
        return true;
    }

    public void draw(Graphics g) {
        if (debugMode)
            g.draw(poly);
        //g.drawImage(img, x, y);
        
        if (type.equals("powerup"))
            g.drawImage(img1, x, y);
        if (type.equals("quest"))
            g.drawImage(img2, x, y);  
        if (type.equals("manual"))
            g.drawImage(img3, x, y);
        
    }
}